<template>
	<view class="tCenter w100">
		<view class="tCenter" v-if="showtext">
		<view class="tCenter pT20 pB20">
			<icon v-if="showico" type="success" color='#09BB07' size="70"/>
			<img v-if="!showico" class="w20" src="../../static/img/news.png" ></img>
		</view>
		<view class="w80 mauto tLeft pT5">
			<view class="f16" v-if="detaildata.name">用户名：{{detaildata.name}}</view>	
			<view class="f16" v-if="detaildata.identitycard">身份证号：{{detaildata.identitycard | isidcard}}</view>	
			<view class="f16" v-if="detaildata.mobile">电话号码：{{detaildata.mobile}}</view>
		<!-- 	<view class="f16" v-if="showtype=='2'">预约时间：{{showtext}}</view>
			<view class="f16" v-if="showtype=='2'">预约公司：{{showtext}}</view> -->
			
			<view class="f16 tCenter" v-if="!detaildata.name">{{showtext}}</view>
			<view class="f16" v-if="detaildata.name">状态：{{showtext}}</view>
		</view>
		</view>
		<backhome></backhome>
		<!-- 加载动画 -->
		<loading v-if="!isloading()"></loading>
	</view>
</template>

<script>
	import {codescancode,arrivearrived_code,appointmentadd_post} from '@/common/api/appointment.js'; //引进requst方法
	import {userinfo}  from '@/common/api/user.js'
	import backhome from '@/components/backhome.vue';
	import  {appointmentinfo} from '@/common/api/appointment.js';
	export default {
		components: {
			backhome
		},
		data() {
			return {
				companyid:"",
				showtext:"",
				detaildata:[],
				id:"",
				departname:"",
				showtype:'1',
				xcode:'',
				showico:false,
				now_reuser:'',
				arrive_status:''
			};
		},
		methods: {

			shodata(){
				

				
							
							
			},
		},
		onLoad(event) {
			let _this=this
			this.showtype=event.showtype;			
			if(this.showtype==2){
				
			}

			this.xcode=event.code;
			appointmentinfo({meeting_code:this.xcode}).then(res=>{
				console.log(res);
				this.now_reuser=res.data.data.now_reuser
				this.arrive_status=res.data.data.appointment_details.arrive_status
				
				if(!this.isloading()){
					return
				}
							
				//arrive_status 状态(1-到达，2-保安放行，3-到达指定位置，4-完成-离开，5-保安拒绝，6 离开部门
				//受访人确认签到请求接口
				//now_reuser   is_app-受访人  is_visiter-访客  is_security-保安
				if(this.now_reuser=='is_app' && this.arrive_status==2 ||  this.now_reuser=='is_visiter' && this.arrive_status==2){
					console.log(this.now_reuser);
					uni.showModal({
						title: '',
						content:'是否确认访客签到',						
						confirmText: "确定",
						success: function (res) {
							
							if (res.confirm) {
								uni.showToast({
									icon:'loading',
									title: '等待处理中...',
								});
								codescancode({icp_sn:_this.xcode}).then(res=>{
									uni.showToast({
										title: '签到成功',
									});	
									if(res.data.code=='200'){									
										_this.showtext=res.data.message;
										_this.showico=true
										if(res.data.data.scanlog){	
													
											_this.detaildata=res.data.data.scanlog[0]
											console.log(_this.detaildata=res.data.data.scanlog[0])
										}
									}else{
										_this.showico=false
										_this.showtext=res.data.message;
									}
								})
							} else{
								uni.navigateTo({
									url:'../user/user'
								})
							}
						}
					});	
					return
				}
				
				//受访人确认访客签离
				
				else if(this.now_reuser=='is_app'  && this.arrive_status==3 ||  this.now_reuser=='is_visiter' && this.arrive_status==3){
					console.log(this.now_reuser);
					uni.showModal({
						title: '',
						content:'是否确认访客签离',						
						confirmText: "确定",
						success: function (res) {
							
							if (res.confirm) {
								uni.showToast({
									icon:'loading',
									title: '等待处理中...',
								});
								codescancode({icp_sn:_this.xcode}).then(res=>{
									uni.showToast({
										title: '签离成功',
									});
									if(res.data.code=='200'){
										_this.showtext=res.data.message;
										_this.showico=true
										if(res.data.data.scanlog){		
											
											_this.detaildata=res.data.data.scanlog[0]
											console.log(_this.detaildata=res.data.data.scanlog[0])
										}
									}else{
										_this.showico=false
										_this.showtext=res.data.message;
									}
								})
							} else if (res.cancel) {
								uni.navigateTo({
									url:'../user/user'
								});
							}
						}
					});	
					return
				}
				
				//保安扫码跳转
				
				else{
					codescancode({icp_sn:this.xcode}).then(res=>{
						if(res.data.code=='200'){
							_this.showtext=res.data.message;
							_this.showico=true
							if(this.showtype==2){
								uni.reLaunch({
								    url: '../securityguard/useraudit?meetingid='+res.data.data[0].id
								});
								return;
							}
							if(res.data.data.scanlog){							
								_this.detaildata=res.data.data.scanlog[0]
								console.log(this.detaildata=res.data.data.scanlog[0])
							}
						}else{
							_this.showico=false
							_this.showtext=res.data.message;
						}
					})
					return
				}
				
			})
					
		},
		onShow(){
			this.showtype=event.showtype;
			this.xcode=event.code;
		
		}
	}
</script>

<style>

</style>
